package com.orange.controller;


import java.sql.SQLException;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.orange.modules.bean.SessionUser;
@Controller
@RequestMapping("/")
public class MainController {
	
	
	@RequestMapping(value = "login", method = RequestMethod.GET)
	public String login(Model model, HttpSession session,HttpServletRequest request){
		String type=(String) request.getSession().getAttribute(SessionUser.SESSION_USER_TYPE);
		if(null!=type){
			if("0".equals(type)){//学校
				return "school_home";
			}else if("1".equals(type)){//材料评审专家
				return "material_home";
			}else if("2".equals(type)){//现场考察专家
				return "scene_home";
			}else if("3".equals(type)){//管理员
				return "admin_home";
			}else{
				return "home_page";
			}
		}else{
			return "home_page";
		}
	}
	
	@RequestMapping(value = "", method = RequestMethod.GET)
	public String sys(Model model, HttpSession session,HttpServletRequest request){
		return "redirect:/home?random="+new Date().getTime();
	}
	
	@RequestMapping(value = "home", method = RequestMethod.GET)
	public String home(Model model, HttpSession session,HttpServletRequest request) throws SQLException{
		String type=(String) request.getSession().getAttribute(SessionUser.SESSION_USER_TYPE);
		if(null!=type){
			if("0".equals(type)){//学校
				return "school_home";
			}else if("1".equals(type)){//材料评审专家
				return "material_home";
			}else if("2".equals(type)){//现场考察专家
				return "scene_home";
			}else if("3".equals(type)){//管理员
				return "admin_home";
			}else{
				return "home_page";
			}
		}else{
			return "home_page";
		}
	}
	
	@RequestMapping(value = "schoolHome", method = RequestMethod.GET)
	public String schoolHome(Model model, HttpSession session,HttpServletRequest request) throws SQLException{
		String type=(String) request.getSession().getAttribute(SessionUser.SESSION_USER_TYPE);
		if(null!=type){
			if("0".equals(type)){//学校
				return "school_home";
			}else if("1".equals(type)){//材料评审专家
				return "material_home";
			}else if("2".equals(type)){//现场考察专家
				return "scene_home";
			}else if("3".equals(type)){//管理员
				return "admin_home";
			}else{
				return "home_page";
			}
		}else{
			return "home_page";
		}
	}
	@RequestMapping(value = "materialHome", method = RequestMethod.GET)
	public String loginSchool(Model model, HttpSession session,HttpServletRequest request) throws SQLException{
		String type=(String) request.getSession().getAttribute(SessionUser.SESSION_USER_TYPE);
		if(null!=type){
			if("0".equals(type)){//学校
				return "school_home";
			}else if("1".equals(type)){//材料评审专家
				return "material_home";
			}else if("2".equals(type)){//现场考察专家
				return "scene_home";
			}else if("3".equals(type)){//管理员
				return "admin_home";
			}else{
				return "home_page";
			}
		}else{
			return "home_page";
		}
		
	}
	
	@RequestMapping(value = "sceneHome", method = RequestMethod.GET)
	public String loginAdmin(Model model, HttpSession session,HttpServletRequest request) throws SQLException{
		String type=(String) request.getSession().getAttribute(SessionUser.SESSION_USER_TYPE);
		if(null!=type){
			if("0".equals(type)){//学校
				return "school_home";
			}else if("1".equals(type)){//材料评审专家
				return "material_home";
			}else if("2".equals(type)){//现场考察专家
				return "scene_home";
			}else if("3".equals(type)){//管理员
				return "admin_home";
			}else{
				return "home_page";
			}
		}else{
			return "home_page";
		}
		
	}
	@RequestMapping(value = "adminHome", method = RequestMethod.GET)
	public String loginInvestiga(Model model, HttpSession session,HttpServletRequest request) throws SQLException{
		String type=(String) request.getSession().getAttribute(SessionUser.SESSION_USER_TYPE);
		if(null!=type){
			if("0".equals(type)){//学校
				return "school_home";
			}else if("1".equals(type)){//材料评审专家
				return "material_home";
			}else if("2".equals(type)){//现场考察专家
				return "scene_home";
			}else if("3".equals(type)){//管理员
				return "admin_home";
			}else{
				return "home_page";
			}
		}else{
			return "home_page";
		}
		
	}
	
	@RequestMapping(value = "leadershipHome", method = RequestMethod.GET)
	public String loginLeader(Model model, HttpSession session,HttpServletRequest request) throws SQLException{
		String type=(String) request.getSession().getAttribute(SessionUser.SESSION_USER_TYPE);
		if(null!=type){
			if("0".equals(type)){//学校
				return "school_home";
			}else if("1".equals(type)){//材料评审专家
				return "material_home";
			}else if("2".equals(type)){//现场考察专家
				return "scene_home";
			}else if("3".equals(type)){//管理员
				return "admin_home";
			}else if("5".equals(type)){
				return "leadership_home";
			}else{
				return "home_page";
			}
		}else{
			return "home_page";
		}
		
	}
	
	@RequestMapping(value = "logout", method = RequestMethod.GET)
	public String logout(Model model, HttpSession session,HttpServletRequest request){
		String pid=(String) request.getSession().getAttribute(SessionUser.SESSION_USER_TYPE);
		if(null!=pid){
			//request.getSession().removeAttribute(SessionUser.SESSION_USER_KEY);
			request.getSession().invalidate();
		}
		return "redirect:/home?random="+new Date().getTime();
	}
	
}


